﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sys_pos_edit.aspx.cs" Inherits="Ccit.SysPlat.Organ.sys_pos_edit" %>

<html>
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/StringClass_Ext.js"></script>
    <script type="text/javascript" src="../script/jwindow.js"></script>
    <script type="text/javascript" src="../script/jsonlib.js"></script>
    <script type="text/javascript">
      <!--
        function doCheck(vType) {
            switch (vType) {
                case "POSNAME":
                    var vOrganId = $get("_hidOrganId").value;
                    var ctrlPosName = $get("txtPosName");
                    var vPosName = jQuery.trim(ctrlPosName.value);
                    if (vPosName == "") {
                        alert("职位名称不能为空!");
                        ctrlPosName.focus();
                    }
                    else {
                        var vPosId = $get("_hidPosId").value;
                        PageMethods.CheckPosNameExist(vPosId, vPosName, vOrganId, ClientCallBack);
                    }
                    break;
                case "ORDER":
                    var ctrlPosOrder = $get("txtPosOrder");
                    var vPosOrder = jQuery.trim(ctrlPosOrder.value);
                    if (vPosOrder != "") {
                        if (!vPosOrder.IsNumber()) {
                            alert("显示顺序只能输入整数!");
                            ctrlPosOrder.focus();
                        }
                    }
                    break;
            }

        }


        function doCheckEmpty() {
            var vOrganId = $get("_hidOrganId").value;
            var ctrlPosName = $get("txtPosName");
            var vPosName = jQuery.trim(ctrlPosName.value);
            if (vPosName == "") {
                alert("职位名称不能为空!");
                ctrlPosName.focus();
                return false;
            }

            var ctrlPosOrder = $get("txtPosOrder");
            var vPosOrder = jQuery.trim(ctrlPosOrder.value);
            if (vPosOrder != "") {
                if (!vPosOrder.IsNumber()) {
                    alert("显示顺序只能输入整数!");
                    ctrlPosOrder.focus();
                    return false;
                }
            }

            return true;
        }

        function ClientCallBack(vResult) {
            if (null == vResult || vResult == "undefined") {
                alert("网络传输错误,没有正确的返回值,请检查网络是否畅通!");
                return;
            }
            eval("var resultObj=" + vResult);
            var operType = resultObj.OPERTYPE;
            switch (operType) {
                case "POSNAMECHECK":
                    if(resultObj.RSTSIGN != "NOEXIST") {
                        alert(resultObj.RSTMSG);
                        var ctrlPosName = $get("txtPosName");
                        ctrlPosName.focus();
                    }
                    break;
                case "POSSAVE":
                    var ctrlType = resultObj.CTRLTYPE;
                    alert(resultObj.RSTMSG);
                    switch (ctrlType) {
                        case "1":
                            var curPosId = $get("_hidPosId").value;
                            var msPos = {};
                            msPos.posId = resultObj.RSTSIGN;
                            msPos.posName = jQuery.trim($get("txtPosName").value);
                            var jsonExpr = JSON.stringify(msPos, function(key, value) { return value; });
                            var isAddNew = (curPosId == "") ? "0" : "1";                            
                            parent.frames[0].document.getElementById("_hidCurPosExpr").value = jsonExpr;
                            parent.frames[0].document.getElementById("_hidAddNewSign").value = isAddNew;
                            parent.frames[0].document.all.btnTrigger.click();
                            $get("_hidPosId").value = resultObj.RSTSIGN;
                            var ctrlDel = $get("btnDel");
                            ctrlDel.style.visibility = "visible";
                            break;
                        case "2":
                            initAddNew();
                            break;
                    }
                    break;
                case "POSDELETE":
                    alert(resultObj.RSTMSG);
                    if (parseInt(resultObj.RSTSIGN) > 0) {
                        var posId = $get("_hidPosId").value;
                        parent.frames[0].document.getElementById("_hidDelPosId").value = posId;
                        parent.frames[0].document.all.btnDelTrigger.click();
//                        initAddNew();
                    }
                    break;
            }
            resultObj = null;           
        }

        function doSave(ctrlType) {
            if (!doCheckEmpty()) return;

            saveData(ctrlType);
        }

        function saveData(ctrlType) {
            var msPos = {};
            msPos.posId = $get("_hidPosId").value;
            msPos.posName = jQuery.trim($get("txtPosName").value);
            msPos.posCode = jQuery.trim($get("txtPosCode").value);
            msPos.posDesc = $get("txtPosDesc").value;
            msPos.orderNo = $get("txtPosOrder").value;

            var msOrgan = {};
            msOrgan.organId = $get("_hidOrganId").value;

            var includeUsers = {};
            includeUsers.key = $get("_hidSelUser").value;

            msPos.belongOrgan = msOrgan;
            msPos.includeUsers = includeUsers;

            var jsonExpr = JSON.stringify(msPos, function(key, value) { return value; });
            PageMethods.SavePosData(jsonExpr,ctrlType, ClientCallBack);

            msPos = null;
        }

        function initAddNew() {
            $get("_hidPosId").value = "";
            $get("txtPosName").value = "";
            $get("txtPosCode").value = "";
            $get("txtPosDesc").value = "";
            $get("_hidSelUser").value = "";
            $get("txtSelUser").value = "";
            $get("txtPosOrder").value = "";

            var ctrlDel = $get("btnDel");
            ctrlDel.style.visibility = "hidden";
        }

        function doDelete() {
            if (!confirm("删除本职位记录,是否继续?")) return;
            var posId = $get("_hidPosId").value;
            PageMethods.DeletePos(posId, ClientCallBack);
        }

        function doSelUser(vCtrlId, vCtrlName) {
            OpenUserMultiSelect(vCtrlId, vCtrlName, "1");
        }
      //-->
    </script>
</head>
<body scroll="no">
    <form id="form1" runat="server">    
    <input type="hidden" id="_hidOrganId" runat="server" />
    <input type="hidden" id="_hidPosId" runat="server" />
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
    </asp:ScriptManager>
    <table class="tableborder" cellpadding="0" cellspacing="0" width="98%" align="center">
            <tr>
                <td width="10%" align="right" class="pformleft"><nobr><font color='red'><b>*</b></font>职位名称</nobr></td>
                <td width="24%" class="pformrightline">
                    <asp:TextBox ID="txtPosName" onchange="doCheck('POSNAME')" CssClass="input" Width="98%" runat="server"></asp:TextBox>
                </td>
                <td width="10%" align="right" class="pformleft"><nobr>职位编号</nobr></td>
                <td width="18%" class="pformrightline">
                    <asp:TextBox ID="txtPosCode" CssClass="input" Width="98%" runat="server"></asp:TextBox>
                </td>
                <td width="10%" align="right" class="pformleft"><nobr>显示顺序</nobr></td>
                <td width="28%" class="pformright">
                    <nobr>
                        <asp:TextBox ID="txtPosOrder" onchange="doCheck('ORDER')" CssClass="input" Width="40px" runat="server"></asp:TextBox>
                        &nbsp;<font color="blue" face='Arial' size='1.5'><i><b>注: 为空则由系统默认生成</b></i></font>
                    </nobr>
                </td>
            </tr>
            <tr>
                <td width="10%" align="right" valign="top" class="pformleft"><nobr>职位描述</nobr></td>
                <td width="90%" class="pformright" colspan="5">
                    <asp:TextBox ID="txtPosDesc" TextMode="MultiLine" Width="99.3%" Height="80px" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td width="10%" align="right" valign="top" class="pformleft">
                    <nobr>职位成员<br />
                        <a href="javascript:doSelUser('_hidSelUser','txtSelUser')">
                            <img src="../images/toolbar/loginUser.gif" border="0" /></a>
                    </nobr>
                </td>
                <td width="90%" class="pformright" colspan="5">
                    <input type="hidden" id="_hidSelUser" runat="server" />
                    <asp:TextBox ID="txtSelUser" TextMode="MultiLine" Width="99.3%" Height="120px" runat="server"></asp:TextBox>                    
                </td>
            </tr>
            <tr class="pformstrip">
                <td colspan="6" align="center">
                    <input type="button" id="btnSave" class="button" onclick="doSave('1')" value="保存" />
                    &nbsp;
                    <input type="button" id="btnSaveAdd" class="button" onclick="doSave('2')" value="保存并新增" />
                    &nbsp;
                    <input type="button" id="btnDel" class="button" onclick="doDelete()" value="删除" />
                </td>
            </tr>            
        </table>
    </form>
    <script language="javascript" type="text/javascript">
    <!--        
        $(document).ready(function(){
            var posId = $get("_hidPosId").value;
            var ctrlDel = $get("btnDel");
            if (posId == "")
                ctrlDel.style.visibility = "hidden";
            else
                ctrlDel.style.visibility = "visible";
        });
    //-->
    </script>
</body>
</html>
